package com.nervenets.general.event;

import com.nervenets.general.model.SysLogInfo;
import com.nervenets.general.service.SysLogService;
import com.nervenets.general.utils.SpringContextHolder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@Slf4j
@AllArgsConstructor
public class SysLogEventListener {
    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void handle(SysLogEvent event) {
        SysLogInfo source = (SysLogInfo) event.getSource();
        try {
            SysLogService sysLogService = SpringContextHolder.getBean(SysLogService.class);
            sysLogService.log(source);
        } catch (Exception ignored) {
        }
    }
}
